package com.villaday.idf.adapter;

import android.content.Context;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.MessageTypesEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model.V;
import com.villaday.idf.util.SharedPreferencesUtil;

/**
 * 信息分类列表
 */

public class MessageTypeAdapter extends AbsRecyclerViewAdapter<MessageTypesEntity.BodyEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private final String roleType;

    public MessageTypeAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_message_last, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }

    @Override
    public int getItemType(MessageTypesEntity.BodyEntity d) {
        return d.getType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, MessageTypesEntity.BodyEntity d, int position) {
        switch (d.getType()) {

            case 0: {
                holder.bindSimpleDraweeView(R.id.tv_sdv, d.getIconUrl())
                        .bindTextView(R.id.tv_title, d.getMessageTypeText())
                        .bindTextView(R.id.tv_time, d.getNewMessage().getCreateTimeText())
                        .bindTextView(R.id.tv_des, d.getNewMessage().getSubTitle())
                        .bindTextView(R.id.tv_num, d.getBadge()+"")
                        .setViewVisible(R.id.tv_num,(d.getBadge()==0)?View.GONE:View.VISIBLE)
                        .setViewVisible(R.id.view,(position==getDataCount()-1)?View.GONE:View.VISIBLE);

            }
            break;

            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


        }
    }
}
